using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class BillOfMaterialMap : EntityTypeConfiguration<BillOfMaterial>
    {
        public BillOfMaterialMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Assembly)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Item)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("BillOfMaterial");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Assembly).HasColumnName("Assembly");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.QTY).HasColumnName("QTY");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.BillOfMaterials)
                .HasForeignKey(d => d.Assembly);
            this.HasRequired(t => t.Item2)
                .WithMany(t => t.BillOfMaterials1)
                .HasForeignKey(d => d.Item);

        }
    }
}
